<template>
    <button
        :disabled="disabled || loading"
        :class="['loading-button', { 'loading': loading, 'disabled': disabled || loading }]"
        @click="$emit('click')"
    >
        <span v-if="loading" class="spinner"></span>
        <span v-else><slot/></span>
    </button>
</template>

<script setup lang="ts">

defineProps({
    loading: {type: Boolean, default: false},
    disabled: {type: Boolean, default: false},
});
</script>

<style scoped>
.loading-button {
    padding: 12px 20px;
    border-radius: 8px;
    background-color: #4caf50;
    color: white;
    cursor: pointer;
    border: none;
    position: relative;
}

.loading-button.loading {
    background-color: #9ccc65;
}

.loading-button.disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.spinner {
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}
</style>
